n=5
def hasAlternatingBits(n):
    pre=-1
    while n!=0:
        cur=n&1
        print(cur)
        if pre==0:
            if cur==1:
                pre=1
                n>>=1
                continue
            else:
                return False
        if pre==1:
            if cur==0:
                pre=0
                n>>=1
                continue
            else:
                return False
        if pre==-1:
            pre=cur
            n>>=1
    return True

def hasAlternatingBits1(n):
    n=(n^(n>>1))+1
    if (n & (n-1))==0:
        return True
    else:
        return False
print(hasAlternatingBits1(n))